package com.vcs.frm.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class UserNameUtil {

	
	/**
	 * A username is a combination of user's first name + year + month + day + 
	 * @param firstName
	 * @return
	 */
	public static String createUsername(String firstName){
		
	    Calendar cal = Calendar.getInstance();
	    int date = cal.get(Calendar.DATE);
	    int month = cal.get(Calendar.MONTH) + 1; // month starts from 0
	    int year = cal.get(Calendar.YEAR);
	    int minute = cal.get(Calendar.MINUTE);
	    System.out.println("date : " + date);
	    System.out.println("month : " + month);
	    System.out.println("year : " + year);
	    System.out.println("minute : " + minute);
	    String dt = null;
	    String dtString = year + "-" + month + "-" + date  + "-" + minute;
	    DateFormat df = new SimpleDateFormat("yy-MM-dd-mm");
	    try
	    {
	      dt = df.format(df.parse(dtString)).replace("-", "");
	    }
	    catch (ParseException e)
	    {
	      e.printStackTrace();
	    }
	    String username = firstName.trim().toLowerCase() + dt;    
	    System.out.println("Generated Username : " + username);
		
		return username;
	}
}
